package com.aloda.ojquestion.pojo.dto;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.json.JSONUtil;
import com.aloda.ojcommon.domain.entity.JudgeCase;
import com.aloda.ojcommon.domain.entity.JudgeConfig;
import com.aloda.ojcommon.domain.entity.Question;
import com.aloda.ojquestion.pojo.entity.QuestionPrompt;
import lombok.Data;

import java.util.List;

/**
 * @Author aloda
 * @Date 2025/4/26 9:08
 */
@Data
public class QuestionAddDTO {

    /**
     * 标题
     */
    private String title;

    /**
     * 内容
     */
    private String content;

    /**
     * 标签列表（json 数组）
     */
    private List<String> tags;

    /**
     * 题目预设代码
     */
    private List<QuestionPrompt> prompt;

    /**
     * 题目答案
     */
    private String answer;

    /**
     * 判题用例（json 数组）
     */
    private List<JudgeCase> judgeCase;

    /**
     * 判题配置（json 对象）
     */
    private JudgeConfig judgeConfig;

    public static Question toQuestion(QuestionAddDTO questionAddDTO) {
        Question question = BeanUtil.toBeanIgnoreError(questionAddDTO, Question.class);
        question.setTags(JSONUtil.toJsonStr(questionAddDTO.getTags()));
        question.setJudgeCase(JSONUtil.toJsonStr(questionAddDTO.getJudgeCase()));
        question.setJudgeConfig(JSONUtil.toJsonStr(questionAddDTO.getJudgeConfig()));
        question.setPrompt(JSONUtil.toJsonStr(questionAddDTO.getPrompt()));
        return question;
    }
}
